/**
 * @file calculator.h
 * @author TK (timechicken45@gmail.com)
 * @brief calculator main function.
 * @version 1.0
 * @date 2021-12-09
 * 
 * @copyright Copyright (c) 2021
 * 
 */

#ifndef __CALCULATOR_H__
#define __CALCULATOR_H__

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <math.h>

/****************************************************************************/
/****************************程序调试宏***************************************/
/* #define LOG(format, ...) fprintf(stdout, ">> "format"\n", ##__VA_ARGS__) */
#ifdef DEBUG_ENV
#define DEBUG(format, ...) fprintf(stdout, "[file: %s line: %d func: %s]DEBUG>> "format"\n", \
__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#define INFO(format, ...) fprintf(stdout, "[file: %s line: %d func: %s]INFO>> "format"\n", \
__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#define WARN(format, ...) fprintf(stdout, "[file: %s line: %d func: %s]WARN>> "format"\n", \
__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#define ERROR(format, ...) fprintf(stdout, "[file: %s line: %d func: %s]ERROR>> "format"\n", \
__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#define FATAL(format, ...) fprintf(stdout, "[file: %s line: %d func: %s]FATAL>> "format"\n", \
__FILE__, __LINE__, __func__, ##__VA_ARGS__); exit(-1)
#else /* DEVELOPMENT_ENV */
#define DEBUG(format, ...)
#define INFO(format, ...)
#define WARN(format, ...)
#define ERROR(format, ...)
#define FATAL(format, ...) exit(-1)
#endif /* DEVELOPMENT_ENV */
/****************************程序调试宏***************************************/
/****************************************************************************/

extern int16_t g_calculator_error_code;

/* 主要功能和查错api */
char *calculate(char *s);
int calc_check_error_char(char *s);
int calc_check_error_brackets(char *s);

/* 计算操作api */
char *Braces(char *const string);
char *Parenthesis(char *string);
char *operation(char *string, char ch);
char *plus_less(char *string);
char *multiplication_division_remainder(char *string);

/* 字符串操作api */
int strn_replace(char *src, char *old_str, char *new_str);
char *strrpc(char *str, char *oldstr, char *newstr);
int check_numbers(char * const string);
void format_the_entered_string(char *string);

#endif /* __CALCULATOR_H__ */
